package org.gitee.simpleutil.util;

import lombok.extern.slf4j.Slf4j;
import org.gitee.simpleutil.core.excel.EasyExcelPoolTool;
import org.gitee.simpleutil.core.excel.ExcelDataQueryService;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import javax.servlet.http.HttpServletResponse;

/**
 * @Description: easyexcel导出工具
 * @Author: qs
 * @Date: 2023/3/30 0030 13:42
 */

@Slf4j
public class EasyExcelPoolUtil {

    /**
     * excel多线程分片导出，按照文件分片，生成多个excel文件，打包为一个zip文件下载
     *
     * @param queryService     分片数据查询service，需具体业务实现自己的查询逻辑；注意：实现分页查询的参数
     * @param head             easyexcel导出数据类
     * @param exportKind       导出业务类型，控制不同业务导出执行状态
     * @param tempFolderPath   临时存放文件路径
     * @param fileName         文件名
     * @param sheetName        sheet名称
     * @param downloadFileName 前端下载文件名称
     * @param dataCount        导出数据总大小
     * @param response         响应HttpServlet
     * @param <R>              分片查询数据返回类型
     */
    public static <R> void threadWriteShardingByFile(ExcelDataQueryService<R> queryService,
                                                     Class head,
                                                     String exportKind,
                                                     String tempFolderPath,
                                                     String fileName,
                                                     String sheetName,
                                                     String downloadFileName,
                                                     long dataCount,
                                                     ThreadPoolTaskExecutor pool,
                                                     HttpServletResponse response) throws Exception {

        EasyExcelPoolTool.threadWriteShardingByFile(queryService, head, exportKind, tempFolderPath, fileName, sheetName, downloadFileName, dataCount, pool, response);
    }

}
